﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
using CGShaderIntegration;

namespace Aufgabe_6_Planets
{
    class EnglertMichael : DrawableGameComponent, IMatrices
    {

        private Matrix viewMatrix, projectionMatrix;
        private Game game;
        SpriteBatch spriteBatch;
        // Planeten
        EnglertMichaelSonne sun;
        EnglertMichaelErde earth;
        EnglertMichaelMond moon;



        public Matrix WorldMatrix
        {
            get
            {
                return this.sun.WorldMatrix;
            }
            set
            {
                this.sun.WorldMatrix = value;
                this.earth.WorldMatrix = value;
                this.moon.WorldMatrix = value;
            }
        }

        public Matrix ViewMatrix
        {
            get
            {
                return this.sun.ViewMatrix;
            }
            set
            {
                this.sun.ViewMatrix = value;
                this.earth.ViewMatrix = value;
                this.moon.ViewMatrix = value;
            }
        }

        public Matrix ProjectionMatrix
        {
            get
            {
                return this.sun.ProjectionMatrix;
            }
            set
            {
                this.sun.ProjectionMatrix = value;
                this.earth.ProjectionMatrix = value;
                this.moon.ProjectionMatrix = value;
            }
        }




        public String GetName()
        {
            return ("EnglertMichael");
        }



        public EnglertMichael(Game game)
            : base(game)
        {
            this.game = game;
            // TODO: Construct any child components here
            Game.Components.Add(this);
        }



        public override void Initialize()
        {
            // setzen der ViewMatrix
            viewMatrix = Matrix.CreateLookAt(new Vector3(0, 0, 25), new Vector3(0, 0, -1), Vector3.Up);
            // setzen der Projektionsmatrix 
            projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                              (float)Game.GraphicsDevice.Viewport.Width / (float)Game.GraphicsDevice.Viewport.Height,
                               1.0f, 1000f);

            // Erzeugen der Planeten und in Components aufnehmen
            sun = new EnglertMichaelSonne(game);
            game.Components.Add(sun);

            earth = new EnglertMichaelErde(game, viewMatrix, projectionMatrix, WorldMatrix);
            game.Components.Add(earth);

            moon = new EnglertMichaelMond(game, viewMatrix, projectionMatrix, WorldMatrix);
            game.Components.Add(moon);

            base.Initialize();
        }



        protected override void LoadContent()
        {

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            base.LoadContent();

        }



        // Ändert die Drehrichtung des Planeten
        public void reverse()
        {

        }



        public override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                game.Exit();

            KeyboardState newState = Keyboard.GetState();

            // Is the SPACE key down?
            if (newState.IsKeyDown(Keys.Space))
            {
                earth.reverse();
                moon.reverse();
            }

            base.Update(gameTime);
        }



        public override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);
            base.Draw(gameTime);
        }


    }
}
